/* identifyButton chrli*/
define([
    'dojo/_base/declare',
    'dojo/_base/lang',
    'esri/InfoTemplate',
    'dojo/topic',
    "dojo/dom-construct"
], function (declare, lang, InfoTemplate, topic) {

    return declare(null, {
        map: null,
        state:null,
        identify:false,
        growlTemplate: '当前状态为{state}',
        constructor: function (options, node) {
            this.options = options;
            this.parentNode = node;
        },
        startup: function () {
            //button样式外面定义，只在里面定义功能
            document.getElementById('identifyButton').addEventListener("click", lang.hitch(this, '_stateToggle'));
            map = this.options.map;
            topic.subscribe('mapClickMode/resetToggleState', lang.hitch(this, 'resetToggleState'));
            //this.own(topic.subscribe('mapClickMode/resetToggleState', lang.hitch(this, 'resetToggleState')));
        },
        resetToggleState:function () {
            this.identify=false;
            //清空查询的边框
            map.infoWindow.clearFeatures();
            dojo.removeClass(document.getElementById('panState'), 'displayNone');
            dojo.addClass(document.getElementById('identifyState'), 'displayNone');
            topic.publish('mapClickMode/setDefault');
        },
        _stateToggle:function () {
            if(!this.identify)
            {
                this.identify=true;
                state='查询状态';
                dojo.addClass(document.getElementById('panState'), 'displayNone');
                dojo.removeClass(document.getElementById('identifyState'), 'displayNone');
                //改变地图状态 clickmode
                topic.publish('growler/growl', {
                    title: '当前操作状态',
                    message: lang.replace(this.growlTemplate, this.state),
                    level: 'default', //can be: 'default', 'warning', 'info', 'error', 'success'.
                    timeout: 3000, //set to 0 for no timeout
                    opacity: 0.8
                });
                topic.publish('mapClickMode/currentSet', 'identify');
            }else {
                this.identify=false;
                map.infoWindow.clearFeatures();
                state='平移状态';
                dojo.removeClass(document.getElementById('panState'), 'displayNone');
                dojo.addClass(document.getElementById('identifyState'), 'displayNone');
                topic.publish('growler/growl', {
                    title: '当前操作状态',
                    message: lang.replace(this.growlTemplate, this.state),
                    level: 'default', //can be: 'default', 'warning', 'info', 'error', 'success'.
                    timeout: 3000, //set to 0 for no timeout
                    opacity: 0.8
                });
                topic.publish('mapClickMode/setDefault');
            }
        }
    });
});